<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>perlreapi - Perl regular expression plugin interface - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/perlreapi">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlreapi.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/perlreapi">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/perlreapi">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/perlreapi">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/perlreapi">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/perlreapi">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/perlreapi">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/perlreapi">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/perlreapi">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/perlreapi">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/perlreapi">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/perlreapi">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/perlreapi">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/perlreapi">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/perlreapi">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/perlreapi">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/perlreapi">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/perlreapi">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/perlreapi">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/perlreapi">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/perlreapi">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/perlreapi">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/perlreapi">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/perlreapi">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/perlreapi">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/perlreapi">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/perlreapi">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/perlreapi">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/perlreapi">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/perlreapi">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/perlreapi">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/perlreapi">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/perlreapi">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/perlreapi">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/perlreapi">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/perlreapi">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/perlreapi">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/perlreapi">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/perlreapi">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/perlreapi">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/perlreapi">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/perlreapi">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/perlreapi">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/perlreapi">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/perlreapi">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/perlreapi">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/perlreapi">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/perlreapi">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/perlreapi">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/perlreapi">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/perlreapi">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/perlreapi">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/perlreapi">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/perlreapi">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/perlreapi">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/perlreapi">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/perlreapi">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/perlreapi">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/perlreapi">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/perlreapi">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/perlreapi">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/perlreapi">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/perlreapi">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/perlreapi">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/perlreapi">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/perlreapi">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/perlreapi">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/perlreapi">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/perlreapi">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/perlreapi">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/perlreapi">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/perlreapi">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/perlreapi">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/perlreapi">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/perlreapi">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/perlreapi">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/perlreapi">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/perlreapi">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/perlreapi">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/perlreapi">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/perlreapi">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlreapi.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/perlreapi">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/perlreapi">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/perlreapi">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/perlreapi">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/perlreapi">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/perlreapi">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/perlreapi">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/perlreapi">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/perlreapi">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/perlreapi">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/perlreapi">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/perlreapi">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/perlreapi">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/perlreapi">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/perlreapi">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/perlreapi">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/perlreapi">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/perlreapi">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/perlreapi">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/perlreapi">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/perlreapi">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/perlreapi">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/perlreapi">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/perlreapi">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/perlreapi">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/perlreapi">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/perlreapi">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/perlreapi">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/perlreapi">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/perlreapi">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/perlreapi">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/perlreapi">5.35.1</a>
          <a class="dropdown-item active" href="perlreapi.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="perlreapi.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="perlreapi.html">perlreapi</a>
          <div id="more">
            (<a href="perlreapi.txt">source</a>,
            <a href="https://metacpan.org/pod/perlreapi">CPAN</a>)
          </div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#DESCRIPTION">DESCRIPTION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#Callbacks">Callbacks</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#comp">comp</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#exec">exec</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#intuit">intuit</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#checkstr">checkstr</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#free">free</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#Numbered-capture-callbacks">Numbered capture callbacks</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#numbered_buff_FETCH">numbered_buff_FETCH</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#numbered_buff_STORE">numbered_buff_STORE</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#numbered_buff_LENGTH">numbered_buff_LENGTH</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#Named-capture-callbacks">Named capture callbacks</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#named_buff">named_buff</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#named_buff_iter">named_buff_iter</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#qr_package">qr_package</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#dupe">dupe</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#op_comp">op_comp</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#The-REGEXP-structure">The REGEXP structure</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#engine">engine</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#mother_re">mother_re</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#extflags">extflags</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#minlen-minlenret">minlen minlenret</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#gofs">gofs</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#substrs">substrs</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#nparens,-lastparen,-and-lastcloseparen">nparens, lastparen, and lastcloseparen</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#intflags">intflags</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#pprivate">pprivate</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#offs">offs</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#precomp-prelen">precomp prelen</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#paren_names">paren_names</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#substrs1">substrs</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#subbeg-sublen-saved_copy-suboffset-subcoffset">subbeg sublen saved_copy suboffset subcoffset</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#wrapped-wraplen">wrapped wraplen</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#seen_evals">seen_evals</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#refcnt">refcnt</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#HISTORY">HISTORY</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#AUTHORS">AUTHORS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="perlreapi.html#LICENSE">LICENSE</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="perlreapi.html#NAME">#</a>NAME</h1>

<p>perlreapi - Perl regular expression plugin interface</p>

<h1 id="DESCRIPTION"><a class="permalink" href="perlreapi.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>As of Perl 5.9.5 there is a new interface for plugging and using regular expression engines other than the default one.</p>

<p>Each engine is supposed to provide access to a constant structure of the following format:</p>

<pre><code>    typedef struct regexp_engine {
        REGEXP* (*comp) (pTHX_
                         const SV * const pattern, const U32 flags);
        I32     (*exec) (pTHX_
                         REGEXP * const rx,
                         char* stringarg,
                         char* strend, char* strbeg,
                         SSize_t minend, SV* sv,
                         void* data, U32 flags);
        char*   (*intuit) (pTHX_
                           REGEXP * const rx, SV *sv,
			   const char * const strbeg,
                           char *strpos, char *strend, U32 flags,
                           struct re_scream_pos_data_s *data);
        SV*     (*checkstr) (pTHX_ REGEXP * const rx);
        void    (*free) (pTHX_ REGEXP * const rx);
        void    (*numbered_buff_FETCH) (pTHX_
                                        REGEXP * const rx,
                                        const I32 paren,
                                        SV * const sv);
        void    (*numbered_buff_STORE) (pTHX_
                                        REGEXP * const rx,
                                        const I32 paren,
                                        SV const * const value);
        I32     (*numbered_buff_LENGTH) (pTHX_
                                         REGEXP * const rx,
                                         const SV * const sv,
                                         const I32 paren);
        SV*     (*named_buff) (pTHX_
                               REGEXP * const rx,
                               SV * const key,
                               SV * const value,
                               U32 flags);
        SV*     (*named_buff_iter) (pTHX_
                                    REGEXP * const rx,
                                    const SV * const lastkey,
                                    const U32 flags);
        SV*     (*qr_package)(pTHX_ REGEXP * const rx);
    #ifdef USE_ITHREADS
        void*   (*dupe) (pTHX_ REGEXP * const rx, CLONE_PARAMS *param);
    #endif
        REGEXP* (*op_comp) (...);</code></pre>

<p>When a regexp is compiled, its <code>engine</code> field is then set to point at the appropriate structure, so that when it needs to be used Perl can find the right routines to do so.</p>

<p>In order to install a new regexp handler, <code>$^H{regcomp}</code> is set to an integer which (when casted appropriately) resolves to one of these structures. When compiling, the <code>comp</code> method is executed, and the resulting <code>regexp</code> structure&#39;s engine field is expected to point back at the same structure.</p>

<p>The pTHX_ symbol in the definition is a macro used by Perl under threading to provide an extra argument to the routine holding a pointer back to the interpreter that is executing the regexp. So under threading all routines get an extra argument.</p>

<h1 id="Callbacks"><a class="permalink" href="perlreapi.html#Callbacks">#</a>Callbacks</h1>

<h2 id="comp"><a class="permalink" href="perlreapi.html#comp">#</a>comp</h2>

<pre><code>REGEXP* comp(pTHX_ const SV * const pattern, const U32 flags);</code></pre>

<p>Compile the pattern stored in <code>pattern</code> using the given <code>flags</code> and return a pointer to a prepared <code>REGEXP</code> structure that can perform the match. See <a href="perlreapi.html#The-REGEXP-structure">&quot;The REGEXP structure&quot;</a> below for an explanation of the individual fields in the REGEXP struct.</p>

<p>The <code>pattern</code> parameter is the scalar that was used as the pattern. Previous versions of Perl would pass two <code>char*</code> indicating the start and end of the stringified pattern; the following snippet can be used to get the old parameters:</p>

<pre><code>STRLEN plen;
char*  exp = SvPV(pattern, plen);
char* xend = exp + plen;</code></pre>

<p>Since any scalar can be passed as a pattern, it&#39;s possible to implement an engine that does something with an array (<code>&quot;ook&quot; =~ [ qw/ eek hlagh / ]</code>) or with the non-stringified form of a compiled regular expression (<code>&quot;ook&quot; =~ qr/eek/</code>). Perl&#39;s own engine will always stringify everything using the snippet above, but that doesn&#39;t mean other engines have to.</p>

<p>The <code>flags</code> parameter is a bitfield which indicates which of the <code>msixpn</code> flags the regex was compiled with. It also contains additional info, such as if <code>use locale</code> is in effect.</p>

<p>The <code>eogc</code> flags are stripped out before being passed to the comp routine. The regex engine does not need to know if any of these are set, as those flags should only affect what Perl does with the pattern and its match variables, not how it gets compiled and executed.</p>

<p>By the time the comp callback is called, some of these flags have already had effect (noted below where applicable). However most of their effect occurs after the comp callback has run, in routines that read the <code>rx-&gt;extflags</code> field which it populates.</p>

<p>In general the flags should be preserved in <code>rx-&gt;extflags</code> after compilation, although the regex engine might want to add or delete some of them to invoke or disable some special behavior in Perl. The flags along with any special behavior they cause are documented below:</p>

<p>The pattern modifiers:</p>

<dl>

<dt id="/m-RXf_PMf_MULTILINE"><a class="permalink" href="perlreapi.html#/m-RXf_PMf_MULTILINE">#</a><a id="m---RXf_PMf_MULTILINE"></a><code>/m</code> - RXf_PMf_MULTILINE</dt>
<dd>

<p>If this is in <code>rx-&gt;extflags</code> it will be passed to <code>Perl_fbm_instr</code> by <code>pp_split</code> which will treat the subject string as a multi-line string.</p>

</dd>
<dt id="/s-RXf_PMf_SINGLELINE"><a class="permalink" href="perlreapi.html#/s-RXf_PMf_SINGLELINE">#</a><a id="s---RXf_PMf_SINGLELINE"></a><code>/s</code> - RXf_PMf_SINGLELINE</dt>
<dd>

</dd>
<dt id="/i-RXf_PMf_FOLD"><a class="permalink" href="perlreapi.html#/i-RXf_PMf_FOLD">#</a><a id="i---RXf_PMf_FOLD"></a><code>/i</code> - RXf_PMf_FOLD</dt>
<dd>

</dd>
<dt id="/x-RXf_PMf_EXTENDED"><a class="permalink" href="perlreapi.html#/x-RXf_PMf_EXTENDED">#</a><a id="x---RXf_PMf_EXTENDED"></a><code>/x</code> - RXf_PMf_EXTENDED</dt>
<dd>

<p>If present on a regex, <code>&quot;#&quot;</code> comments will be handled differently by the tokenizer in some cases.</p>

<p>TODO: Document those cases.</p>

</dd>
<dt id="/p-RXf_PMf_KEEPCOPY"><a class="permalink" href="perlreapi.html#/p-RXf_PMf_KEEPCOPY">#</a><a id="p---RXf_PMf_KEEPCOPY"></a><code>/p</code> - RXf_PMf_KEEPCOPY</dt>
<dd>

<p>TODO: Document this</p>

</dd>
<dt id="Character-set"><a class="permalink" href="perlreapi.html#Character-set">#</a><a id="Character"></a>Character set</dt>
<dd>

<p>The character set rules are determined by an enum that is contained in this field. This is still experimental and subject to change, but the current interface returns the rules by use of the in-line function <code>get_regex_charset(const U32 flags)</code>. The only currently documented value returned from it is REGEX_LOCALE_CHARSET, which is set if <code>use locale</code> is in effect. If present in <code>rx-&gt;extflags</code>, <code>split</code> will use the locale dependent definition of whitespace when RXf_SKIPWHITE or RXf_WHITE is in effect. ASCII whitespace is defined as per <a href="perlapi.html#isSPACE">isSPACE</a>, and by the internal macros <code>is_utf8_space</code> under UTF-8, and <code>isSPACE_LC</code> under <code>use locale</code>.</p>

</dd>
</dl>

<p>Additional flags:</p>

<dl>

<dt id="RXf_SPLIT"><a class="permalink" href="perlreapi.html#RXf_SPLIT">#</a>RXf_SPLIT</dt>
<dd>

<p>This flag was removed in perl 5.18.0. <code>split &#39; &#39;</code> is now special-cased solely in the parser. RXf_SPLIT is still #defined, so you can test for it. This is how it used to work:</p>

<p>If <code>split</code> is invoked as <code>split &#39; &#39;</code> or with no arguments (which really means <code>split(&#39; &#39;, $_)</code>, see <a href="perlfunc.html#split">split</a>), Perl will set this flag. The regex engine can then check for it and set the SKIPWHITE and WHITE extflags. To do this, the Perl engine does:</p>

<pre><code>if (flags &amp; RXf_SPLIT &amp;&amp; r-&gt;prelen == 1 &amp;&amp; r-&gt;precomp[0] == &#39; &#39;)
    r-&gt;extflags |= (RXf_SKIPWHITE|RXf_WHITE);</code></pre>

</dd>
</dl>

<p>These flags can be set during compilation to enable optimizations in the <code>split</code> operator.</p>

<dl>

<dt id="RXf_SKIPWHITE"><a class="permalink" href="perlreapi.html#RXf_SKIPWHITE">#</a>RXf_SKIPWHITE</dt>
<dd>

<p>This flag was removed in perl 5.18.0. It is still #defined, so you can set it, but doing so will have no effect. This is how it used to work:</p>

<p>If the flag is present in <code>rx-&gt;extflags</code> <code>split</code> will delete whitespace from the start of the subject string before it&#39;s operated on. What is considered whitespace depends on if the subject is a UTF-8 string and if the <code>RXf_PMf_LOCALE</code> flag is set.</p>

<p>If RXf_WHITE is set in addition to this flag, <code>split</code> will behave like <code>split &quot; &quot;</code> under the Perl engine.</p>

</dd>
<dt id="RXf_START_ONLY"><a class="permalink" href="perlreapi.html#RXf_START_ONLY">#</a>RXf_START_ONLY</dt>
<dd>

<p>Tells the split operator to split the target string on newlines (<code>\n</code>) without invoking the regex engine.</p>

<p>Perl&#39;s engine sets this if the pattern is <code>/^/</code> (<code>plen == 1 &amp;&amp; *exp == &#39;^&#39;</code>), even under <code>/^/s</code>; see <a href="perlfunc.html">split</a>. Of course a different regex engine might want to use the same optimizations with a different syntax.</p>

</dd>
<dt id="RXf_WHITE"><a class="permalink" href="perlreapi.html#RXf_WHITE">#</a>RXf_WHITE</dt>
<dd>

<p>Tells the split operator to split the target string on whitespace without invoking the regex engine. The definition of whitespace varies depending on if the target string is a UTF-8 string and on if RXf_PMf_LOCALE is set.</p>

<p>Perl&#39;s engine sets this flag if the pattern is <code>\s+</code>.</p>

</dd>
<dt id="RXf_NULL"><a class="permalink" href="perlreapi.html#RXf_NULL">#</a>RXf_NULL</dt>
<dd>

<p>Tells the split operator to split the target string on characters. The definition of character varies depending on if the target string is a UTF-8 string.</p>

<p>Perl&#39;s engine sets this flag on empty patterns, this optimization makes <code>split //</code> much faster than it would otherwise be. It&#39;s even faster than <code>unpack</code>.</p>

</dd>
<dt id="RXf_NO_INPLACE_SUBST"><a class="permalink" href="perlreapi.html#RXf_NO_INPLACE_SUBST">#</a>RXf_NO_INPLACE_SUBST</dt>
<dd>

<p>Added in perl 5.18.0, this flag indicates that a regular expression might perform an operation that would interfere with inplace substitution. For instance it might contain lookbehind, or assign to non-magical variables (such as $REGMARK and $REGERROR) during matching. <code>s///</code> will skip certain optimisations when this is set.</p>

</dd>
</dl>

<h2 id="exec"><a class="permalink" href="perlreapi.html#exec">#</a>exec</h2>

<pre><code>I32 exec(pTHX_ REGEXP * const rx,
         char *stringarg, char* strend, char* strbeg,
         SSize_t minend, SV* sv,
         void* data, U32 flags);</code></pre>

<p>Execute a regexp. The arguments are</p>

<dl>

<dt id="rx"><a class="permalink" href="perlreapi.html#rx">#</a>rx</dt>
<dd>

<p>The regular expression to execute.</p>

</dd>
<dt id="sv"><a class="permalink" href="perlreapi.html#sv">#</a>sv</dt>
<dd>

<p>This is the SV to be matched against. Note that the actual char array to be matched against is supplied by the arguments described below; the SV is just used to determine UTF8ness, <code>pos()</code> etc.</p>

</dd>
<dt id="strbeg"><a class="permalink" href="perlreapi.html#strbeg">#</a>strbeg</dt>
<dd>

<p>Pointer to the physical start of the string.</p>

</dd>
<dt id="strend"><a class="permalink" href="perlreapi.html#strend">#</a>strend</dt>
<dd>

<p>Pointer to the character following the physical end of the string (i.e. the <code>\0</code>, if any).</p>

</dd>
<dt id="stringarg"><a class="permalink" href="perlreapi.html#stringarg">#</a>stringarg</dt>
<dd>

<p>Pointer to the position in the string where matching should start; it might not be equal to <code>strbeg</code> (for example in a later iteration of <code>/.../g</code>).</p>

</dd>
<dt id="minend"><a class="permalink" href="perlreapi.html#minend">#</a>minend</dt>
<dd>

<p>Minimum length of string (measured in bytes from <code>stringarg</code>) that must match; if the engine reaches the end of the match but hasn&#39;t reached this position in the string, it should fail.</p>

</dd>
<dt id="data"><a class="permalink" href="perlreapi.html#data">#</a>data</dt>
<dd>

<p>Optimisation data; subject to change.</p>

</dd>
<dt id="flags"><a class="permalink" href="perlreapi.html#flags">#</a>flags</dt>
<dd>

<p>Optimisation flags; subject to change.</p>

</dd>
</dl>

<h2 id="intuit"><a class="permalink" href="perlreapi.html#intuit">#</a>intuit</h2>

<pre><code>    char* intuit(pTHX_
		REGEXP * const rx,
		SV *sv,
		const char * const strbeg,
		char *strpos,
		char *strend,
		const U32 flags,
		struct re_scream_pos_data_s *data);</code></pre>

<p>Find the start position where a regex match should be attempted, or possibly if the regex engine should not be run because the pattern can&#39;t match. This is called, as appropriate, by the core, depending on the values of the <code>extflags</code> member of the <code>regexp</code> structure.</p>

<p>Arguments:</p>

<pre><code class="plaintext">    rx:     the regex to match against
    sv:     the SV being matched: only used for utf8 flag; the string
	    itself is accessed via the pointers below. Note that on
	    something like an overloaded SV, SvPOK(sv) may be false
	    and the string pointers may point to something unrelated to
	    the SV itself.
    strbeg: real beginning of string
    strpos: the point in the string at which to begin matching
    strend: pointer to the byte following the last char of the string
    flags   currently unused; set to 0
    data:   currently unused; set to NULL</code></pre>

<h2 id="checkstr"><a class="permalink" href="perlreapi.html#checkstr">#</a>checkstr</h2>

<pre><code>SV*	checkstr(pTHX_ REGEXP * const rx);</code></pre>

<p>Return a SV containing a string that must appear in the pattern. Used by <code>split</code> for optimising matches.</p>

<h2 id="free"><a class="permalink" href="perlreapi.html#free">#</a>free</h2>

<pre><code>void free(pTHX_ REGEXP * const rx);</code></pre>

<p>Called by Perl when it is freeing a regexp pattern so that the engine can release any resources pointed to by the <code>pprivate</code> member of the <code>regexp</code> structure. This is only responsible for freeing private data; Perl will handle releasing anything else contained in the <code>regexp</code> structure.</p>

<h2 id="Numbered-capture-callbacks"><a class="permalink" href="perlreapi.html#Numbered-capture-callbacks">#</a><a id="Numbered"></a>Numbered capture callbacks</h2>

<p>Called to get/set the value of <code>$`</code>, <code>$&#39;</code>, <code>$&amp;</code> and their named equivalents, ${^PREMATCH}, ${^POSTMATCH} and ${^MATCH}, as well as the numbered capture groups (<code>$1</code>, <code>$2</code>, ...).</p>

<p>The <code>paren</code> parameter will be <code>1</code> for <code>$1</code>, <code>2</code> for <code>$2</code> and so forth, and have these symbolic values for the special variables:</p>

<pre><code class="plaintext">${^PREMATCH}  RX_BUFF_IDX_CARET_PREMATCH
${^POSTMATCH} RX_BUFF_IDX_CARET_POSTMATCH
${^MATCH}     RX_BUFF_IDX_CARET_FULLMATCH
$`            RX_BUFF_IDX_PREMATCH
$&#39;            RX_BUFF_IDX_POSTMATCH
$&amp;            RX_BUFF_IDX_FULLMATCH</code></pre>

<p>Note that in Perl 5.17.3 and earlier, the last three constants were also used for the caret variants of the variables.</p>

<p>The names have been chosen by analogy with <a href="./Tie::Scalar.html">Tie::Scalar</a> methods names with an additional <b>LENGTH</b> callback for efficiency. However named capture variables are currently not tied internally but implemented via magic.</p>

<h3 id="numbered_buff_FETCH"><a class="permalink" href="perlreapi.html#numbered_buff_FETCH">#</a>numbered_buff_FETCH</h3>

<pre><code>void numbered_buff_FETCH(pTHX_ REGEXP * const rx, const I32 paren,
                         SV * const sv);</code></pre>

<p>Fetch a specified numbered capture. <code>sv</code> should be set to the scalar to return, the scalar is passed as an argument rather than being returned from the function because when it&#39;s called Perl already has a scalar to store the value, creating another one would be redundant. The scalar can be set with <code>sv_setsv</code>, <code>sv_setpvn</code> and friends, see <a href="perlapi.html">perlapi</a>.</p>

<p>This callback is where Perl untaints its own capture variables under taint mode (see <a href="perlsec.html">perlsec</a>). See the <code>Perl_reg_numbered_buff_fetch</code> function in <i>regcomp.c</i> for how to untaint capture variables if that&#39;s something you&#39;d like your engine to do as well.</p>

<h3 id="numbered_buff_STORE"><a class="permalink" href="perlreapi.html#numbered_buff_STORE">#</a>numbered_buff_STORE</h3>

<pre><code>void    (*numbered_buff_STORE) (pTHX_
                                REGEXP * const rx,
                                const I32 paren,
                                SV const * const value);</code></pre>

<p>Set the value of a numbered capture variable. <code>value</code> is the scalar that is to be used as the new value. It&#39;s up to the engine to make sure this is used as the new value (or reject it).</p>

<p>Example:</p>

<pre><code>if (&quot;ook&quot; =~ /(o*)/) {
    # &#39;paren&#39; will be &#39;1&#39; and &#39;value&#39; will be &#39;ee&#39;
    $1 =~ tr/o/e/;
}</code></pre>

<p>Perl&#39;s own engine will croak on any attempt to modify the capture variables, to do this in another engine use the following callback (copied from <code>Perl_reg_numbered_buff_store</code>):</p>

<pre><code>void
Example_reg_numbered_buff_store(pTHX_
                                REGEXP * const rx,
                                const I32 paren,
                                SV const * const value)
{
    PERL_UNUSED_ARG(rx);
    PERL_UNUSED_ARG(paren);
    PERL_UNUSED_ARG(value);

    if (!PL_localizing)
        Perl_croak(aTHX_ PL_no_modify);
}</code></pre>

<p>Actually Perl will not <i>always</i> croak in a statement that looks like it would modify a numbered capture variable. This is because the STORE callback will not be called if Perl can determine that it doesn&#39;t have to modify the value. This is exactly how tied variables behave in the same situation:</p>

<pre><code>package CaptureVar;
use parent &#39;Tie::Scalar&#39;;

sub TIESCALAR { bless [] }
sub FETCH { undef }
sub STORE { die &quot;This doesn&#39;t get called&quot; }

package main;

tie my $sv =&gt; &quot;CaptureVar&quot;;
$sv =~ y/a/b/;</code></pre>

<p>Because <code>$sv</code> is <code>undef</code> when the <code>y///</code> operator is applied to it, the transliteration won&#39;t actually execute and the program won&#39;t <code>die</code>. This is different to how 5.8 and earlier versions behaved since the capture variables were READONLY variables then; now they&#39;ll just die when assigned to in the default engine.</p>

<h3 id="numbered_buff_LENGTH"><a class="permalink" href="perlreapi.html#numbered_buff_LENGTH">#</a>numbered_buff_LENGTH</h3>

<pre><code>I32 numbered_buff_LENGTH (pTHX_
                          REGEXP * const rx,
                          const SV * const sv,
                          const I32 paren);</code></pre>

<p>Get the <code>length</code> of a capture variable. There&#39;s a special callback for this so that Perl doesn&#39;t have to do a FETCH and run <code>length</code> on the result, since the length is (in Perl&#39;s case) known from an offset stored in <code>rx-&gt;offs</code>, this is much more efficient:</p>

<pre><code>I32 s1  = rx-&gt;offs[paren].start;
I32 s2  = rx-&gt;offs[paren].end;
I32 len = t1 - s1;</code></pre>

<p>This is a little bit more complex in the case of UTF-8, see what <code>Perl_reg_numbered_buff_length</code> does with <a href="perlapi.html#is_utf8_string_loclen">is_utf8_string_loclen</a>.</p>

<h2 id="Named-capture-callbacks"><a class="permalink" href="perlreapi.html#Named-capture-callbacks">#</a><a id="Named"></a>Named capture callbacks</h2>

<p>Called to get/set the value of <code>%+</code> and <code>%-</code>, as well as by some utility functions in <a href="re.html">re</a>.</p>

<p>There are two callbacks, <code>named_buff</code> is called in all the cases the FETCH, STORE, DELETE, CLEAR, EXISTS and SCALAR <a href="./Tie::Hash.html">Tie::Hash</a> callbacks would be on changes to <code>%+</code> and <code>%-</code> and <code>named_buff_iter</code> in the same cases as FIRSTKEY and NEXTKEY.</p>

<p>The <code>flags</code> parameter can be used to determine which of these operations the callbacks should respond to. The following flags are currently defined:</p>

<p>Which <a href="./Tie::Hash.html">Tie::Hash</a> operation is being performed from the Perl level on <code>%+</code> or <code>%+</code>, if any:</p>

<pre><code class="plaintext">RXapif_FETCH
RXapif_STORE
RXapif_DELETE
RXapif_CLEAR
RXapif_EXISTS
RXapif_SCALAR
RXapif_FIRSTKEY
RXapif_NEXTKEY</code></pre>

<p>If <code>%+</code> or <code>%-</code> is being operated on, if any.</p>

<pre><code class="plaintext">RXapif_ONE /* %+ */
RXapif_ALL /* %- */</code></pre>

<p>If this is being called as <code>re::regname</code>, <code>re::regnames</code> or <code>re::regnames_count</code>, if any. The first two will be combined with <code>RXapif_ONE</code> or <code>RXapif_ALL</code>.</p>

<pre><code class="plaintext">RXapif_REGNAME
RXapif_REGNAMES
RXapif_REGNAMES_COUNT</code></pre>

<p>Internally <code>%+</code> and <code>%-</code> are implemented with a real tied interface via <a href="./Tie::Hash::NamedCapture.html">Tie::Hash::NamedCapture</a>. The methods in that package will call back into these functions. However the usage of <a href="./Tie::Hash::NamedCapture.html">Tie::Hash::NamedCapture</a> for this purpose might change in future releases. For instance this might be implemented by magic instead (would need an extension to mgvtbl).</p>

<h3 id="named_buff"><a class="permalink" href="perlreapi.html#named_buff">#</a>named_buff</h3>

<pre><code>SV*     (*named_buff) (pTHX_ REGEXP * const rx, SV * const key,
                       SV * const value, U32 flags);</code></pre>

<h3 id="named_buff_iter"><a class="permalink" href="perlreapi.html#named_buff_iter">#</a>named_buff_iter</h3>

<pre><code>SV*     (*named_buff_iter) (pTHX_
                            REGEXP * const rx,
                            const SV * const lastkey,
                            const U32 flags);</code></pre>

<h2 id="qr_package"><a class="permalink" href="perlreapi.html#qr_package">#</a>qr_package</h2>

<pre><code>SV* qr_package(pTHX_ REGEXP * const rx);</code></pre>

<p>The package the qr// magic object is blessed into (as seen by <code>ref qr//</code>). It is recommended that engines change this to their package name for identification regardless of if they implement methods on the object.</p>

<p>The package this method returns should also have the internal <code>Regexp</code> package in its <code>@ISA</code>. <code>qr//-&gt;isa(&quot;Regexp&quot;)</code> should always be true regardless of what engine is being used.</p>

<p>Example implementation might be:</p>

<pre><code>SV*
Example_qr_package(pTHX_ REGEXP * const rx)
{
	PERL_UNUSED_ARG(rx);
	return newSVpvs(&quot;re::engine::Example&quot;);
}</code></pre>

<p>Any method calls on an object created with <code>qr//</code> will be dispatched to the package as a normal object.</p>

<pre><code>use re::engine::Example;
my $re = qr//;
$re-&gt;meth; # dispatched to re::engine::Example::meth()</code></pre>

<p>To retrieve the <code>REGEXP</code> object from the scalar in an XS function use the <code>SvRX</code> macro, see <a href="perlapi.html#REGEXP-Functions">&quot;REGEXP Functions&quot; in perlapi</a>.</p>

<pre><code>void meth(SV * rv)
PPCODE:
    REGEXP * re = SvRX(sv);</code></pre>

<h2 id="dupe"><a class="permalink" href="perlreapi.html#dupe">#</a>dupe</h2>

<pre><code>void* dupe(pTHX_ REGEXP * const rx, CLONE_PARAMS *param);</code></pre>

<p>On threaded builds a regexp may need to be duplicated so that the pattern can be used by multiple threads. This routine is expected to handle the duplication of any private data pointed to by the <code>pprivate</code> member of the <code>regexp</code> structure. It will be called with the preconstructed new <code>regexp</code> structure as an argument, the <code>pprivate</code> member will point at the <b>old</b> private structure, and it is this routine&#39;s responsibility to construct a copy and return a pointer to it (which Perl will then use to overwrite the field as passed to this routine.)</p>

<p>This allows the engine to dupe its private data but also if necessary modify the final structure if it really must.</p>

<p>On unthreaded builds this field doesn&#39;t exist.</p>

<h2 id="op_comp"><a class="permalink" href="perlreapi.html#op_comp">#</a>op_comp</h2>

<p>This is private to the Perl core and subject to change. Should be left null.</p>

<h1 id="The-REGEXP-structure"><a class="permalink" href="perlreapi.html#The-REGEXP-structure">#</a><a id="The"></a>The REGEXP structure</h1>

<p>The REGEXP struct is defined in <i>regexp.h</i>. All regex engines must be able to correctly build such a structure in their <a href="perlreapi.html#comp">&quot;comp&quot;</a> routine.</p>

<p>The REGEXP structure contains all the data that Perl needs to be aware of to properly work with the regular expression. It includes data about optimisations that Perl can use to determine if the regex engine should really be used, and various other control info that is needed to properly execute patterns in various contexts, such as if the pattern anchored in some way, or what flags were used during the compile, or if the program contains special constructs that Perl needs to be aware of.</p>

<p>In addition it contains two fields that are intended for the private use of the regex engine that compiled the pattern. These are the <code>intflags</code> and <code>pprivate</code> members. <code>pprivate</code> is a void pointer to an arbitrary structure, whose use and management is the responsibility of the compiling engine. Perl will never modify either of these values.</p>

<pre><code>    typedef struct regexp {
        /* what engine created this regexp? */
        const struct regexp_engine* engine;

        /* what re is this a lightweight copy of? */
        struct regexp* mother_re;

        /* Information about the match that the Perl core uses to manage
         * things */
        U32 extflags;   /* Flags used both externally and internally */
	I32 minlen;	/* mininum possible number of chars in */
                           string to match */
	I32 minlenret;	/* mininum possible number of chars in $&amp; */
        U32 gofs;       /* chars left of pos that we search from */

        /* substring data about strings that must appear
           in the final match, used for optimisations */
        struct reg_substr_data *substrs;

        U32 nparens;  /* number of capture groups */

        /* private engine specific data */
        U32 intflags;   /* Engine Specific Internal flags */
        void *pprivate; /* Data private to the regex engine which 
                           created this object. */

        /* Data about the last/current match. These are modified during
         * matching*/
        U32 lastparen;            /* highest close paren matched ($+) */
        U32 lastcloseparen;       /* last close paren matched ($^N) */
        regexp_paren_pair *offs;  /* Array of offsets for (@-) and
                                     (@+) */

        char *subbeg;  /* saved or original string so \digit works
                          forever. */
        SV_SAVED_COPY  /* If non-NULL, SV which is COW from original */
        I32 sublen;    /* Length of string pointed by subbeg */
        I32 suboffset;	/* byte offset of subbeg from logical start of
                           str */
	I32 subcoffset;	/* suboffset equiv, but in chars (for @-/@+) */

        /* Information about the match that isn&#39;t often used */
        I32 prelen;           /* length of precomp */
        const char *precomp;  /* pre-compilation regular expression */

        char *wrapped;  /* wrapped version of the pattern */
        I32 wraplen;    /* length of wrapped */

        I32 seen_evals;   /* number of eval groups in the pattern - for
                             security checks */
        HV *paren_names;  /* Optional hash of paren names */

        /* Refcount of this regexp */
        I32 refcnt;             /* Refcount of this regexp */
    } regexp;</code></pre>

<p>The fields are discussed in more detail below:</p>

<h2 id="engine"><a class="permalink" href="perlreapi.html#engine">#</a><code>engine</code></h2>

<p>This field points at a <code>regexp_engine</code> structure which contains pointers to the subroutines that are to be used for performing a match. It is the compiling routine&#39;s responsibility to populate this field before returning the regexp object.</p>

<p>Internally this is set to <code>NULL</code> unless a custom engine is specified in <code>$^H{regcomp}</code>, Perl&#39;s own set of callbacks can be accessed in the struct pointed to by <code>RE_ENGINE_PTR</code>.</p>

<h2 id="mother_re"><a class="permalink" href="perlreapi.html#mother_re">#</a><code>mother_re</code></h2>

<p>TODO, see commit 28d8d7f41a.</p>

<h2 id="extflags"><a class="permalink" href="perlreapi.html#extflags">#</a><code>extflags</code></h2>

<p>This will be used by Perl to see what flags the regexp was compiled with, this will normally be set to the value of the flags parameter by the <a href="perlreapi.html#comp">comp</a> callback. See the <a href="perlreapi.html#comp">comp</a> documentation for valid flags.</p>

<h2 id="minlen-minlenret"><a class="permalink" href="perlreapi.html#minlen-minlenret">#</a><a id="minlen"></a><code>minlen</code> <code>minlenret</code></h2>

<p>The minimum string length (in characters) required for the pattern to match. This is used to prune the search space by not bothering to match any closer to the end of a string than would allow a match. For instance there is no point in even starting the regex engine if the minlen is 10 but the string is only 5 characters long. There is no way that the pattern can match.</p>

<p><code>minlenret</code> is the minimum length (in characters) of the string that would be found in $&amp; after a match.</p>

<p>The difference between <code>minlen</code> and <code>minlenret</code> can be seen in the following pattern:</p>

<pre><code class="plaintext">/ns(?=\d)/</code></pre>

<p>where the <code>minlen</code> would be 3 but <code>minlenret</code> would only be 2 as the \d is required to match but is not actually included in the matched content. This distinction is particularly important as the substitution logic uses the <code>minlenret</code> to tell if it can do in-place substitutions (these can result in considerable speed-up).</p>

<h2 id="gofs"><a class="permalink" href="perlreapi.html#gofs">#</a><code>gofs</code></h2>

<p>Left offset from pos() to start match at.</p>

<h2 id="substrs"><a class="permalink" href="perlreapi.html#substrs">#</a><code>substrs</code></h2>

<p>Substring data about strings that must appear in the final match. This is currently only used internally by Perl&#39;s engine, but might be used in the future for all engines for optimisations.</p>

<h2 id="nparens,-lastparen,-and-lastcloseparen"><a class="permalink" href="perlreapi.html#nparens,-lastparen,-and-lastcloseparen">#</a><a id="nparens"></a><a id="nparens-lastparen-and-lastcloseparen"></a><code>nparens</code>, <code>lastparen</code>, and <code>lastcloseparen</code></h2>

<p>These fields are used to keep track of: how many paren capture groups there are in the pattern; which was the highest paren to be closed (see <a href="perlvar.html#%24%2B">&quot;$+&quot; in perlvar</a>); and which was the most recent paren to be closed (see <a href="perlvar.html#%24%5EN">&quot;$^N&quot; in perlvar</a>).</p>

<h2 id="intflags"><a class="permalink" href="perlreapi.html#intflags">#</a><code>intflags</code></h2>

<p>The engine&#39;s private copy of the flags the pattern was compiled with. Usually this is the same as <code>extflags</code> unless the engine chose to modify one of them.</p>

<h2 id="pprivate"><a class="permalink" href="perlreapi.html#pprivate">#</a><code>pprivate</code></h2>

<p>A void* pointing to an engine-defined data structure. The Perl engine uses the <code>regexp_internal</code> structure (see <a href="perlreguts.html#Base-Structures">&quot;Base Structures&quot; in perlreguts</a>) but a custom engine should use something else.</p>

<h2 id="offs"><a class="permalink" href="perlreapi.html#offs">#</a><code>offs</code></h2>

<p>A <code>regexp_paren_pair</code> structure which defines offsets into the string being matched which correspond to the <code>$&amp;</code> and <code>$1</code>, <code>$2</code> etc. captures, the <code>regexp_paren_pair</code> struct is defined as follows:</p>

<pre><code>typedef struct regexp_paren_pair {
    I32 start;
    I32 end;
} regexp_paren_pair;</code></pre>

<p>If <code>-&gt;offs[num].start</code> or <code>-&gt;offs[num].end</code> is <code>-1</code> then that capture group did not match. <code>-&gt;offs[0].start/end</code> represents <code>$&amp;</code> (or <code>${^MATCH}</code> under <code>/p</code>) and <code>-&gt;offs[paren].end</code> matches <code>$$paren</code> where <code>$paren </code>= 1&gt;.</p>

<h2 id="precomp-prelen"><a class="permalink" href="perlreapi.html#precomp-prelen">#</a><a id="precomp"></a><code>precomp</code> <code>prelen</code></h2>

<p>Used for optimisations. <code>precomp</code> holds a copy of the pattern that was compiled and <code>prelen</code> its length. When a new pattern is to be compiled (such as inside a loop) the internal <code>regcomp</code> operator checks if the last compiled <code>REGEXP</code>&#39;s <code>precomp</code> and <code>prelen</code> are equivalent to the new one, and if so uses the old pattern instead of compiling a new one.</p>

<p>The relevant snippet from <code>Perl_pp_regcomp</code>:</p>

<pre><code>	if (!re || !re-&gt;precomp || re-&gt;prelen != (I32)len ||
	    memNE(re-&gt;precomp, t, len))
        /* Compile a new pattern */</code></pre>

<h2 id="paren_names"><a class="permalink" href="perlreapi.html#paren_names">#</a><code>paren_names</code></h2>

<p>This is a hash used internally to track named capture groups and their offsets. The keys are the names of the buffers the values are dualvars, with the IV slot holding the number of buffers with the given name and the pv being an embedded array of I32. The values may also be contained independently in the data array in cases where named backreferences are used.</p>

<h2 id="substrs1"><a class="permalink" href="perlreapi.html#substrs1">#</a><code>substrs</code></h2>

<p>Holds information on the longest string that must occur at a fixed offset from the start of the pattern, and the longest string that must occur at a floating offset from the start of the pattern. Used to do Fast-Boyer-Moore searches on the string to find out if its worth using the regex engine at all, and if so where in the string to search.</p>

<h2 id="subbeg-sublen-saved_copy-suboffset-subcoffset"><a class="permalink" href="perlreapi.html#subbeg-sublen-saved_copy-suboffset-subcoffset">#</a><a id="subbeg"></a><code>subbeg</code> <code>sublen</code> <code>saved_copy</code> <code>suboffset</code> <code>subcoffset</code></h2>

<p>Used during the execution phase for managing search and replace patterns, and for providing the text for <code>$&amp;</code>, <code>$1</code> etc. <code>subbeg</code> points to a buffer (either the original string, or a copy in the case of <code>RX_MATCH_COPIED(rx)</code>), and <code>sublen</code> is the length of the buffer. The <code>RX_OFFS</code> start and end indices index into this buffer.</p>

<p>In the presence of the <code>REXEC_COPY_STR</code> flag, but with the addition of the <code>REXEC_COPY_SKIP_PRE</code> or <code>REXEC_COPY_SKIP_POST</code> flags, an engine can choose not to copy the full buffer (although it must still do so in the presence of <code>RXf_PMf_KEEPCOPY</code> or the relevant bits being set in <code>PL_sawampersand</code>). In this case, it may set <code>suboffset</code> to indicate the number of bytes from the logical start of the buffer to the physical start (i.e. <code>subbeg</code>). It should also set <code>subcoffset</code>, the number of characters in the offset. The latter is needed to support <code>@-</code> and <code>@+</code> which work in characters, not bytes.</p>

<h2 id="wrapped-wraplen"><a class="permalink" href="perlreapi.html#wrapped-wraplen">#</a><a id="wrapped"></a><code>wrapped</code> <code>wraplen</code></h2>

<p>Stores the string <code>qr//</code> stringifies to. The Perl engine for example stores <code>(?^:eek)</code> in the case of <code>qr/eek/</code>.</p>

<p>When using a custom engine that doesn&#39;t support the <code>(?:)</code> construct for inline modifiers, it&#39;s probably best to have <code>qr//</code> stringify to the supplied pattern, note that this will create undesired patterns in cases such as:</p>

<pre><code>my $x = qr/a|b/;  # &quot;a|b&quot;
my $y = qr/c/i;   # &quot;c&quot;
my $z = qr/$x$y/; # &quot;a|bc&quot;</code></pre>

<p>There&#39;s no solution for this problem other than making the custom engine understand a construct like <code>(?:)</code>.</p>

<h2 id="seen_evals"><a class="permalink" href="perlreapi.html#seen_evals">#</a><code>seen_evals</code></h2>

<p>This stores the number of eval groups in the pattern. This is used for security purposes when embedding compiled regexes into larger patterns with <code>qr//</code>.</p>

<h2 id="refcnt"><a class="permalink" href="perlreapi.html#refcnt">#</a><code>refcnt</code></h2>

<p>The number of times the structure is referenced. When this falls to 0, the regexp is automatically freed by a call to <code>pregfree</code>. This should be set to 1 in each engine&#39;s <a href="perlreapi.html#comp">&quot;comp&quot;</a> routine.</p>

<h1 id="HISTORY"><a class="permalink" href="perlreapi.html#HISTORY">#</a>HISTORY</h1>

<p>Originally part of <a href="perlreguts.html">perlreguts</a>.</p>

<h1 id="AUTHORS"><a class="permalink" href="perlreapi.html#AUTHORS">#</a>AUTHORS</h1>

<p>Originally written by Yves Orton, expanded by Ævar Arnfjörð Bjarmason.</p>

<h1 id="LICENSE"><a class="permalink" href="perlreapi.html#LICENSE">#</a>LICENSE</h1>

<p>Copyright 2006 Yves Orton and 2007 Ævar Arnfjörð Bjarmason.</p>

<p>This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
